package com.jams.goodox.activity.serve;


import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.hangzhou.jin.customview.LoadView;
import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.adapter.CustomFragmentPagerAdapter;
import com.jams.goodox.constant.H5UrlConstants;
import com.jams.goodox.entity.OrderTypeInfo;
import com.jams.goodox.utils.StringUtils;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.widget.TypePopupWindow;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

import static com.jams.goodox.R.id.mPager;

/**
 * ***介绍
 */
public class TownIntroduceActivity extends BaseActivity {
    @Bind(R.id.lv_load)
    LoadView emptyView;
    @Bind(R.id.tabs)
    TabLayout enterprisePolicyTabLayout;
    @Bind(mPager)
    ViewPager enterprisePolicyPager;
    @Bind(R.id.iv_select)
    ImageView ivSelect;
    @Bind(R.id.ll_tabs)
    LinearLayout llTabs;

    private List<Fragment> contentList = new ArrayList<>();
    private FragmentPagerAdapter adapter;
    /**
     * popwindow的显示状态
     */
    private boolean isShow = false;
    /**
     * 显示popwindow的数据
     */
    private List<OrderTypeInfo> typeInfos = new ArrayList<>();
    /**
     * 选择的item的条目
     */
    private int selectPosition = 0;
    
    @Override
    protected int getLayoutId() {
        return R.layout.activity_personnel_policy; 
    }

    @Override
    protected void init() {
        llTabs.setVisibility(View.VISIBLE);
        StyleUtil.titleBackKey(this,"***介绍");
        //***介绍的tittle
        List<String> tittleList = new ArrayList<>();
        
        tittleList.add("***地图");
        tittleList.add("基本概况");
        tittleList.add("***位置");
        tittleList.add("入驻企业");
        tittleList.add("联系我们");
        contentList = new ArrayList<>();
        contentList.add( TownIntroduceH5Fragment.newInstance(H5UrlConstants.map));//***地图
        contentList.add( TownIntroduceH5Fragment.newInstance(H5UrlConstants.base));//基本情况
        contentList.add( TownIntroduceH5Fragment.newInstance(H5UrlConstants.location));//***位置
        contentList.add( TownIntroduceH5Fragment.newInstance(H5UrlConstants.company));//入驻企业
        contentList.add( TownIntroduceH5Fragment.newInstance(H5UrlConstants.contact));//联系我们
        adapter = new CustomFragmentPagerAdapter(getSupportFragmentManager(), tittleList, contentList);
        
        enterprisePolicyPager.setAdapter(adapter);
        enterprisePolicyPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                selectPosition = position;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        enterprisePolicyTabLayout.setupWithViewPager(enterprisePolicyPager);
        emptyView.loadCompleteNoData(R.mipmap.holder_no_common,R.string.no_content);
        for (String typeStr : tittleList) {
            OrderTypeInfo info = new OrderTypeInfo();
            info.setTypeName(StringUtils.newString(typeStr));
            typeInfos.add(info);
        }
        
    }
    @OnClick(R.id.iv_select)
    public void onViewClicked() {

        //显示popwindow
        if (isShow) {
            isShow = false;
            ivSelect.setImageResource(R.mipmap.pop_down);
            TypePopupWindow.getInstance().dismissPop();

            //隐藏popwindow
        } else {
            isShow = true;
            ivSelect.setImageResource(R.mipmap.icon_menu_close);
            TypePopupWindow.getInstance().showTabTypePopupWindow(enterprisePolicyTabLayout, mContext, typeInfos, new TypePopupWindow.DataChangeListener() {
                @Override
                public void change(int position) {
                    selectPosition = position;
                    enterprisePolicyPager.setCurrentItem(position);
                }

                @Override
                public void dismiss() {
                    isShow = false;
                    ivSelect.setImageResource(R.mipmap.pop_down);

                }
            }, selectPosition);
        }


    }
}
